package com.zmkj.taobao.taobaoproductservice.controller;


import com.zmkj.taobao.taobaoproductservice.entity.Product;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/ProductController")
public class ProductController {
    @RequestMapping("/selectById/{orderId}")
    public List queryProductByOrderId(@PathVariable(value = "orderId") Integer orderId){
        List<Product> productList = new ArrayList<>();
        Product product1 = new Product(1,"iphone11",12000.9,1000,4);
        Product product2 = new Product(2,"iphone12",13000.9,2000,3);
        Product product3 = new Product(3,"iphone13",14000.9,3000,2);
        Product product4 = new Product(4,"iphone14",15000.9,4000,1);
        productList.add(product1);
        productList.add(product2);
        productList.add(product3);
        productList.add(product4);
        for (int i = 0;i<productList.size();i++){
            if(productList.get(i).getOrderId()!=orderId){
                productList.remove(i--);
            }
        }
        return productList;
    }
}
